//
//  LZMyTableViewButtonView.m
//  laziz_Consumer
//
//  Created by ZhaoDongBo on 2016/10/27.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZMyTableViewButtonView.h"

#import "Masonry.h"

@implementation LZMyTableViewButtonView

- (instancetype)initWithButtonType:(LZ_MY_TABLEVIEW_BUTTON_TYPE)type{
    
    self = [super init];
    if (self) {
        [self setup:type];
    }
    
    return self;
}

- (void)setup:(LZ_MY_TABLEVIEW_BUTTON_TYPE)type {
    
    [self addSubview:self.myButton];
    
    if (type == LZ_MY_TABLEVIEW_BUTTON_TYPE_QUIT) {
        [self.myButton setTitle:LZLocalizedString(@"quit", nil) forState:UIControlStateNormal];
    }
    else {
        [self.myButton setTitle:LZLocalizedString(@"nextstep", nil) forState:UIControlStateNormal];
    }
    
    [self.myButton makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(40);
        make.leading.mas_equalTo(10);
        make.trailing.mas_equalTo(-10);
        make.height.mas_equalTo(40);
        
    }];
}

- (void)buttonAction:(UIButton *)sender {
    if (_didButtonActionBlock) {
        self.didButtonActionBlock(sender);
    }
}

- (UIButton *)myButton {

    if (_myButton == nil) {
        _myButton = [[UIButton alloc] init];
        _myButton.backgroundColor       = UIColorFromRGB(0x33a928, 1);
        _myButton.layer.masksToBounds   = YES;
        _myButton.layer.cornerRadius    = 20.0;
        [_myButton setTitleColor:UIColorFromRGB(0xffffff, 1) forState:UIControlStateNormal];
        [_myButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _myButton;
}

@end
